package windbell.domain.common

import edu.fudan.mylang.pf.IObjectFactory
import edu.fudan.mylang.pf.query.IQueryCriteria
import java.util.Collection
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class ContextAwareEntities {
	@Autowired IObjectFactory entities
	@Autowired Collection<IContextAwareObjectInitService> objectInitServices;
	def <S, T extends IQueryCriteria<S>> T createContextAwareQueryCriteria(Class<T> c){
		entities.createQueryCriteria(c)=>[criteria|
			objectInitServices.findFirst[it.isMyContextAwareObject(criteria)]?.initContext(criteria)
		]
	}
}

//@Service
//class HospitalContextAwareObjectInitService implements IContextAwareObjectInitService{
//	
////	@Autowired IHospitalContextService hospitalContextService
////
////	override initContext(Object contextAwareObject) {
////		(contextAwareObject as IHospitalContextAware)=>[
////			it.hospital = hospitalContextService.hospitalContext
////		]
////	}
////	
////	override isMyContextAwareObject(Object contextAwareObject) {
////		contextAwareObject instanceof IHospitalContextAware
////	}
//	
//}